package demo4;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-08-02
 * Time: 15:19
 */
public class TestDemo {

    public static Object locker1 = new Object();
    public static Object locker2 = new Object();
    public static Object locker3 = new Object();

    public static void main(String[] args) throws InterruptedException {
        //Arrays.sort();
        Thread a = new Thread(()->{
                try {
                    synchronized(locker1) {
                        locker1.wait();
                    }
                    System.out.println("a");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
        });
        a.start();
        Thread b = new Thread(()->{
                try {
                    synchronized (locker2) {
                        locker2.wait();
                    }
                    System.out.println("b");
                    synchronized (locker1) {
                        locker1.notify();
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
        });
        b.start();
        Thread c = new Thread(()->{
                try {
                    synchronized (locker3) {
                        locker3.wait();
                    }
                    System.out.println("c");
                    synchronized (locker2) {
                        locker2.notify();
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
        });
        c.start();

        Thread.sleep(1000);
        synchronized (locker3){
            locker3.notify();
        }
    }

}
